package com.jie;
import com.im.LinkIMServerApplication;
import com.im.entity.vo.GroupVO;
import com.im.service.IImGroupService;
import com.im.utils.Redis.RedisBatch.RedisBatchSequenceGenerator;
import com.im.utils.Redis.RedisSequenceGenerator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
import java.util.List;
@SpringBootTest(classes = LinkIMServerApplication.class)
@RunWith(SpringRunner.class)
public class main_test {
    @Autowired
    private RedisSequenceGenerator generator;
    @Autowired
    private RedisBatchSequenceGenerator redisBatchGenerator;
    @Autowired
    private RedisSequenceGenerator redisSequenceGenerator;
    @Autowired
    private IImGroupService imGroupService;
    @Test
    public void test_id_generator() {
        long startTime = System.currentTimeMillis();
        //  for (int i = 0; i < 400; i++) {
        //      generator.getNextSequence((long) 3);
        //  } // 记录结束时间
        List<Long> SeqArr = redisBatchGenerator.getNextSequencesPipeline((long) 5, 50000);
        long endTime = System.currentTimeMillis();

        // 计算并输出运行时间
        System.out.println("For loop took " + (endTime - startTime)/1000 + " s generate arr("+"size:"+ SeqArr.size()+") range from "+SeqArr.get(0)+" to "+SeqArr.get(SeqArr.size()-1));
    }
        //100个id-->7s
        //300个id-->21s
        //400个id-->27s
        //500个id-->34s
        //30000个id-->1840s
    @Test
    public void test_id_generator2() {
        List<Long> SeqArr=new ArrayList<>();
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < 100; i++) redisSequenceGenerator.getNextSequence((long) 6);
        long endTime = System.currentTimeMillis();
        System.out.println("For loop took " + (endTime - startTime)/1000.0);
        // 计算并输出运行时间
        // System.out.println("For loop took " + (endTime - startTime)/1000 + " s generate arr("+"size:"+ SeqArr.size()+") range from "+SeqArr.get(0)+" to "+SeqArr.get(SeqArr.size()-1));
        //500个id->33.878s
        //300个id->20.916s
        //100个id->6.597s
    }
    @Test
    public void testCreateGroup(){
        GroupVO groupVO = new GroupVO(2L, "testGroup",  "testGroup");
        imGroupService.createGroup(groupVO);
    }

    @Test
    public void testUpdateGroup(){
        GroupVO groupVO = new GroupVO(2L, "testGroupxxxx",  "testGroupxxxx");
        imGroupService.modifyGroup(groupVO);
    }
}
